<template>
  <div >
    <a-form-model class="fromModels" ref="withdrawPaySettingModel" layout="vertical" 
    :labelCol="{span: 5}" :wrapperCol="{span: 12}">
        <a-form-model-item label="类型">
          <a-select v-model="type">
            <a-select-option v-for="(item,index) in selects" :key="index" :value="item.id">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-model-item>

        <div v-if="type=='1'">
          <a-form-model-item  label="四方代付的app_id" :rules ="[
            {required: true, message: '请输入四方代付的app_id', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms1.app_id"  placeholder="请输入四方代付的app_id" />
          </a-form-model-item>
          <a-form-model-item  label="四方代付的sign_type" :rules ="[
            {required: true, message: '请输入四方代付的sign_type', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms1.sign_type"  placeholder="请输入四方代付的sign_type" />
          </a-form-model-item>
          <a-form-model-item label="四方代付的secret" :rules ="[
            {required: true, message: '请输入四方代付的secret', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms1.secret"  placeholder="请输入四方代付的secret" />
          </a-form-model-item>
          <a-form-model-item label="四方代付的回调地址" :rules ="[
            {required: true, message: '请输入四方代付的回调地址', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms1.notify_url"  placeholder="请输入四方代付的回调地址" />
          </a-form-model-item>
        </div>

        <div v-if="type=='2'">
          <a-form-model-item  label="商户协议号" :rules ="[
            {required: true, message: '请输入商户协议号', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms2.merchantno"  placeholder="请输入商户协议号" />
          </a-form-model-item>
          <a-form-model-item label="商户key" :rules ="[
            {required: true, message: '请输入商户key', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms2.merkey"  placeholder="请输入商户key" />
          </a-form-model-item>
          <a-form-model-item label="记账本ID" :rules ="[
            {required: true, message: '请输入记账本ID', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms2.bookno"  placeholder="请输入记账本ID" />
          </a-form-model-item>
          <a-form-model-item  label="回调地址" :rules ="[
            {required: true, message: '请输入回调地址', trigger: 'blur'}
          ]">
            <a-input v-model="withdrawPaySettingFroms2.notifyurl"  placeholder="请输入回调地址" />
          </a-form-model-item>
        </div>


        <a-form-model-item :wrapper-col="{ span: 12, offset:5 }">
          <a-button type="primary" @click="whites">提交</a-button>
        </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
import {getWithdrawalGetType,updateWithdrawalGetType } from '@/api/system.js'
export default {
  name: 'withdrawPaySetting',
  
  data() {
      return {
        type:"0",
        withdrawPaySettingFroms1:{
          app_id:"",
          notify_url:"",
          secret:"",
          sign_type:"",
        },
        withdrawPaySettingFroms2:{
          bookno:"",
          merchantno:"",
          merkey:"",
          notifyurl:"",
        },
        selects:[
          {id:'0',name:"线下打款"},
          {id:'1',name:"四方代付"},
          {id:'2',name:"代付公司"},
        ]
      }
  },
  created(){
    this.getPrivacyAgreementInfo()
  },
  methods:{
    getPrivacyAgreementInfo(){
      getWithdrawalGetType({
        brand_id: process.env.VUE_APP_BRAND_ID,
      }).then(res=>{
        if(res.data){
          this.type=res.data.type
          if(res.data.type=='1'){
            this.withdrawPaySettingFroms1=res.data
          }
          if(res.data.type=='2'){
            this.withdrawPaySettingFroms2=res.data
          }
        }else{
          this.type='0'
        }
      })
    },
    whites(){
      var json={
        type:this.type,
        brand_id: process.env.VUE_APP_BRAND_ID,
      }
      if(this.type=='1'){
        json={
          type:this.type,
          ...this.withdrawPaySettingFroms1
        }
      }
      if(this.type=='2'){
        json={
          type:this.type,
          ...this.withdrawPaySettingFroms2
        }
      }

      updateWithdrawalGetType(json).then(res=>{
        this.$message.success("操作成功");
      })
    },
  }
}
</script>

<style lang="less" scoped>
</style>
